package com.admin.dao;

import com.admin.bean.Order;
import com.admin.bean.Radio;
import com.admin.util.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class radioDao {
    public List<Radio> selectRadio(){
        List<Radio> radios=new ArrayList<Radio>();
        try{
            Connection connection = JDBCUtils.getConnection();
            String sql ="select *from `radio`";
            PreparedStatement ps=connection.prepareStatement(sql);
            ResultSet resultSet=ps.executeQuery();
            while (resultSet.next()){
                Radio radio=new Radio();
                radio.setRadioId(resultSet.getString(1));
                radio.setRadioDescribe(resultSet.getString(2));
                radios.add(radio);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return radios;
    }
    public boolean deleteRadio(String radioId){
        try {
            Connection connection= JDBCUtils.getConnection();
//            flightId="'"+flightId+"'";
            String sql="delete from `radio` where radioId in ("+radioId+")";
            Statement st=connection.createStatement();
//            System.out.println(orderId+"\n"+sql);
            st.executeUpdate(sql);
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return true;
    }
    public boolean addRadio(Radio radio){
        try{
            Connection connection= JDBCUtils.getConnection();
            String sql="INSERT INTO `radio` VALUES (?,?) ";
            PreparedStatement ps=connection.prepareStatement(sql);
            ps.setString(1,radio.getRadioId());
            ps.setString(2,radio.getRadioDescribe());
            ps.execute();
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }

}
